package com.hangwei.paperless.adapter.sub;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseViewHolder;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.BatchSheet;
import com.hangwei.paperless.widget.MyTextWatcher;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/11/28.
 */

public class BatchSheetAdapter extends MyAdapter<BatchSheet, BaseViewHolder> {
    public BatchSheetAdapter(@Nullable List<BatchSheet> data) {
        super(R.layout.item_batch_sheet, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final BatchSheet item) {
        helper.setIsRecyclable(false);
        helper.setText(R.id.tvSeq, Tools.checkedString(item.seq))
                .setText(R.id.tvPN, Tools.checkedString(item.pn))
                .setText(R.id.tvIPL, Tools.checkedString(item.iplNo))
                .setText(R.id.tvNeedQty, Tools.checkedString(item.reqdQty))
                .setText(R.id.tvQty, Tools.checkedString(item.recdQty))
                .setText(R.id.etRemark, Tools.checkedString(item.remark))
                .setText(R.id.tvDes, Tools.checkedString(item.description));
        helper.setOnClickListener(R.id.ivAdd, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int qty = Integer.parseInt(item.recdQty);
                qty++;
                item.recdQty = String.valueOf(qty);
                helper.setText(R.id.tvQty, Tools.checkedString(item.recdQty));
            }
        }).setOnClickListener(R.id.ivReduce, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int qty = Integer.parseInt(item.recdQty);
                if (qty>1){
                    qty--;
                    item.recdQty = String.valueOf(qty);
                    helper.setText(R.id.tvQty, Tools.checkedString(item.recdQty));
                }
            }
        });
        EditText etRemark = helper.getView(R.id.etRemark);
        etRemark.addTextChangedListener(new MyTextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                item.remark = s.toString().trim();
            }
        });
    }
}
